{% extends 'base.html' %}
{% block link %}
    <link href="/static/dist/css/pcmanager.css" rel="stylesheet" type="text/css">
{% endblock %}

{% block body %}
    <div class="wrapper wrapper-content animated fadeInRight">
			    <div class="row">
			        <div class="col-lg-12">
			            <div class="ibox float-e-margins" id="all">
			                <div class="ibox-title shezhiye">
			                    <h3> 软件包管理页</h3>
			                    <h5> *添加,更新,软件包</h5>
			                </div>
							<div class="col-lg-12">
			                <div class="ibox-content">
			                        <div class="col-sm-6 ibox-title" style="padding-left: 0">
			                            <a href="#pageModal" class="btn btn-sm btn-primary " data-toggle="modal" data-placement="bottom"><span class="glyphicon-plus"></span> 添加软件包 </a>
			                            <!--<a href="#" class="btn btn-sm btn-warning " data-toggle="modal" data-placement="bottom"><span class="glyphicon glyphicon-check"></span> 推送全部 </a>-->
			                        </div>
			                        <!--添加机器弹窗-->
						            <div class="modal fade" id="pageModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
									  <div class="modal-dialog">
									    <div class="modal-content">
									      <div class="modal-header">
									        <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
									        <h4 class="modal-title" id="myModalLabel">添加软件包</h4>
									      </div>
									      <div class="modal-body">
                                              <form role="form" method="post" enctype="multipart/form-data" id="pageapp" >
                                                  {% csrf_token %}
{#                                                {{uf.username}}#}
{#                                                {{uf.headImg}}#}
{#                                                <input type="submit" value="ok"/>#}
{#                                                </form>#}
{#									        <form role="form" action="/page/" method="post" id="pageapp">{% csrf_token %}#}
{##}
									            <div class="form-group">
												    <label for="exampleInputFile">上传软件包</label>
{#												    <input type="file" id="exampleInputFile" name="exampleInputFile">#}
                                                    {{uf.headImg}}
												    <p class="help-block">软件包上传位置：/upload</p>
												</div>
												<div class="control-group">
									                <label class="control-label" for="description">备注：</label>
									                <div class="controls">

{#                                                        {{uf.username}}#}
									                    <input class="form-control" id="description" name="description" placeholder="请输入备注信息" type="text" />
									                </div>
									            </div>
									        </form>
									      </div>
									      <div class="modal-footer">
									        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
									        <button type="submit" form="pageapp" class="btn btn-primary" value="submit">提交</button>
									      </div>
										</div>
									</div>
									</div>
						            <!--弹窗结束-->
			                        <div id="export"></div>
			                        <table class=" table table-striped table-bordered table-hover " id="editable" name="editable">
			                            <thead>
			                                <tr>
			                                    <th class="text-center"> 软件包名</th>
			                                 <th class="text-center"> 备注</th>
			                                    <th class="text-center"> 操作 </th>
			                                </tr>
			                            </thead>
			                            <tbody>
                                        {% for item in contacts %}
                                            <tr class="gradeX">
			                                    <td class="text-center hostname">{{ item.rpm_name }}</td>
			                                    <td class="text-center">{{ item.description }}</td>
			                                    <td class="text-center fenge" data-editable='false'>
                                                    <button  type="button" class="btn btn-xs btn-danger asset_del" onclick="del_page(this,{{ item.id }});" >删除</button>
			                                    </td>
			                                </tr>
                                        {% endfor %}
			                            </tbody>
			                        </table>
			                </div>
			                </div>
			            </div>
			        </div>
			    </div>
        </div>
{% endblock %}
{% block javascript %}
<script src="/static/dist/js/jquery.cookie.js"></script>
    <script>
    var csrftoken = $.cookie('csrftoken');
	function csrfSafeMethod(method) {
		// these HTTP methods do not require CSRF protection
		return (/^(GET|HEAD|OPTIONS|TRACE)$/.test(method));
	}
	$.ajaxSetup({
		beforeSend: function(xhr, settings) {
			if (!csrfSafeMethod(settings.type) && !this.crossDomain) {
				xhr.setRequestHeader("X-CSRFToken", csrftoken);
			}
		}
	});
        function del_page(doc,id) {
{#                    $("#devid").attr("value",id);#}
                $.ajax({
                    url:'/delpage/',
                    type:'POST',
                    data:{modify:id},
                    success:function (arg) {
                        window.location.reload();
                        var obj = jQuery.parseJSON(arg);
                        var this_id = $(doc).attr('id');
                        console.log(this_id);
                        console.log(obj.status);
                    },
                    error:function () {
                        console.log('failed');
                    }
                });
            };
    </script>
{% endblock %}